public class Node{
    public int value;
    public Node left;
    public Node right;
    public Node (int data){
        this.value=data;
    }
}

public void printEdge1(Node head){
    if(head==null)return;
    int height=getHeight(head,0);
    Node[][] edgeMap=new Node[height][2];
    setEdgeMap(head,0,edgeMap);
    //left
    for(int i=0;i!=edgeMap.length;i++){
        System.out.print(edgeMap[i][0].value+" ");
    }
    printNotInMap(head,0,edgeMap);
    //right
    for(int i=edgeMap.length-1;i!=-1;i--){
        if(edgeMap[i][0]!=edgeMap[i][1]){
            System.out.print(edgeMap[i][1].value+" ");
        }
    }
}


public int getHeight(Node h,int l){
    if(h==null){
        return l;
    }
    return Math.max(getHeight(h.left,l+1),getHeight(h.right,l+1));
}

public void setEdgeMap(Node h, int l, Node[][] edgeMap){
    if(h==null){
        return;
    }

    edgeMap[l][0]=edgeMap[l][0]==null?h:edgeMap[l][0];
    edgeMap[l][1]=h;
    setEdgeMap(h.left,l+1,edgeMap);
    setEdgeMap(h.right,l+1,edgeMap);
}


public void printNotInMap(Node h,int l, Node[][] edgeMap){
    if(h==null)return;
    if(h.right==null&&h.left==null&&h.value!=edgeMap[l][0]&&h.value!=edgeMap[l][1]){
        System.out.print(h.value+" ");
    }
    printNotInMap(h.left,l+1,edgeMap);
    printNotInMap(h.right,l+1,edgeMap);
}